package com.lhys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lhys.mapper.AssetBrandMapper;
import com.lhys.pojo.AssetBrand;
import com.lhys.service.AssetBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 资产_品牌表 服务实现类
 * </p>
 *
 * @author 小七
 * @since 2021-05-06
 */
@Service
public class AssetBrandServiceImpl implements AssetBrandService {
    @Autowired
    private AssetBrandMapper brandMapper;

    @Override
    @Transactional
    public Boolean saveAssetBrand(AssetBrand assetBrand) {
        try {
            if (assetBrand.getId() == null) {
                if (assetBrand.getCreateTime() == null) {
                    assetBrand.setCreateTime(new Date());
                }
                return brandMapper.addAssetBrand(assetBrand) > 0;
            }
            return brandMapper.updateAssetBrand(assetBrand) > 0;
        } catch (Exception e) {
            System.out.println("重复添加");
            return null;
        }
    }

    @Override
    @Transactional
    public Boolean delAssetBrandById(Integer id) {
        return brandMapper.delAssetBrand(id) > 0;
    }

    @Override
    public AssetBrand getAssetBrandById(Integer id) {
        return brandMapper.getAssetBrandById(id);
    }

    @Override
    public PageInfo<AssetBrand> getAssetBrandList(AssetBrand assetBrand, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AssetBrand> list = brandMapper.getAssetBrandByCodeAndTitleOrRemarkList(assetBrand);
        PageInfo<AssetBrand> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
